﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Main_Inventory_TransactionFormat_TransFormat : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    string strsql = "";
    string TFOID="";
    string AccTypeId = "";
    string FinYear = "";
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind_TransType();
            panelJrnlType.Visible = false;
            chkBillLevelTariff.Visible = false;

        }
        if (Session["userid"] == null)
        {
            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "redirect", "window.open('../../login.aspx','_parent');", true);
            Response.Redirect("~/SessionExpired.aspx");
        }
        //Reset_chekbox();
    }
    //1 - Stock Journal, 2 - Production Journal, 3 - Stock Issue, 4 - Stock Receipt, 5 - Stock Transfer (5th one applicable if multi-location is ON); 6 - Physical Stock ',
    
    protected void Bind_TransType()
    {
        strsql = "select id,trantype from IVR_TRANSTYPE where active='True' order by TRANTYPE ASC";
        DataTable Dt = DU.getdata(strsql);
        ddlTransaction.DataSource = Dt;
        ddlTransaction.DataTextField = "trantype";
        ddlTransaction.DataValueField = "id";
        ddlTransaction.DataBind();
        ddlTransaction.Items.Insert(0,new ListItem("-Select Transaction-","0"));
        ddlTransaction.SelectedValue = "0";        
    }
    
    protected void chkAmtIncTax_CheckedChanged(object sender, EventArgs e)
    {

        if (chkAmtIncTax.Checked == true)
        {
            chkPreTax.Checked = false;
            chkPostTax.Checked = false;
            chkPreTax.Enabled = false;
            chkPostTax.Enabled = false;

        }
        else if (chkAmtIncTax.Checked == false)
        {
            chkPreTax.Enabled = true;
            chkPostTax.Enabled = true;
        }
    }
    protected void chkCenvat_CheckedChanged(object sender, EventArgs e)
    {
        if (chkCenvat.Checked == true)
        {
            chkBillLevelTariff.Visible = true;
        }
        else if (chkCenvat.Checked == false)
        {
            chkBillLevelTariff.Checked = false;
            chkBillLevelTariff.Visible = false;
        }

    }
    protected void chkReference_CheckedChanged(object sender, EventArgs e)
    {
        if (chkReference.Checked == true)
        {
            panelReference.Enabled = true;
            txtRefHeading1.Enabled = true;
            txtRefHeading2.Enabled = true;
            txtRefHeading3.Enabled = true;
            txtRefHeading4.Enabled = true;
        }
        else if (chkReference.Checked == false)
        {
            panelReference.Enabled = false;
            txtRefHeading1.Enabled = false;
            txtRefHeading2.Enabled = false;
            txtRefHeading3.Enabled = false;
            txtRefHeading4.Enabled = false;
        }
    }
    protected void chkBillLevelTariff_CheckedChanged(object sender, EventArgs e)
    {
        if (chkBillLevelTariff.Checked == true)
        {
            panelTariffHeading.Enabled = true;
            txtTariffHeading.Enabled = true;
            txtTariffSubHeading.Enabled = true;
            txtTariffDescription.Enabled = true;
        }
        else if (chkBillLevelTariff.Checked == false)
        {
            panelTariffHeading.Enabled = false;
            txtTariffHeading.Enabled = false;
            txtTariffSubHeading.Enabled = false;
            txtTariffDescription.Enabled = false;
        }
    }
    protected void Reset_chekbox()
    {
        //Reset checkbox
        chkPrepareBy.Checked = false;
        chkCheckBy.Checked = false;
        chkAuthorized.Checked = false;
        chkRemark.Checked=false;
        chkNote.Checked = false;
        chkNarration.Checked = false;
        chkDelivery.Checked = false;
        chkReference.Checked = false;
        chkRateAmount.Checked = false;
        chkTrackPending.Checked = false;
        chkPrint.Checked = false;
        chkGenerateVat.Checked = false;
        chkTermConditions.Checked = false;
        chkPreTax.Checked = false;
        chkPostTax.Checked = false;
        chkDefualNarration.Checked = false;
        chkAmtIncTax.Checked = false;
        chkCenvat.Checked = false;
        chkBillLevelTariff.Checked = false;
        chkPostBillTCS.Checked = false;
        chkAddDescItem.Checked = false;
    }
    protected void chkShowItemName_CheckedChanged(object sender, EventArgs e)
    {
        if (chkShowItemName.Checked == true)
        {
            chkShowItemCode.Checked = false;
        }
        else if (chkShowItemName.Checked == false)
        {
            chkShowItemCode.Checked = true;           
        }
    }
    protected void chkShowItemCode_CheckedChanged(object sender, EventArgs e)
    {
        if (chkShowItemCode.Checked == true)
        {
            chkShowItemName.Checked = false;
        }
        else if (chkShowItemCode.Checked == false)
        {
            chkShowItemName.Checked = true;
        }
    }
    protected void ddlTransaction_SelectedIndexChanged1(object sender, EventArgs e)
    {
        

        if (ddlTransaction.SelectedValue == "1")// Sales Invoice
        {
           
            lblHeading.Text = "Invoice Heading";
            Reset_chekbox();
           
            //************Tab Tax & Discount***********//
            panelDiscount.Enabled = true;
            radioDBillLevel.Enabled = true;
            radioDItemLevel.Enabled = true;            
            radioDNone.Enabled = true;            
            radioTBillLevel.Checked = true;
            radioTBillLevel.Enabled = true;
            radioTItemLevel.Enabled = true;
            txtRoundoff.Enabled = true;
            txtDiscount.Enabled = true;

            radioDNone.Checked = true;
            radioDItemLevel.Checked = false;
            radioDBillLevel.Checked = false;
            radioTItemLevel.Checked = false;

            //************Tab Tax & Discount***********//
            
            chkAmtIncTax.Enabled = true;
            chkPreTax.Enabled = true;
            chkPostTax.Enabled = true;
            chkDelivery.Enabled = true;
            chkReference.Enabled = true;
            chkTermConditions.Enabled = true;
            chkPrepareBy.Enabled = true;
            chkCheckBy.Enabled = true;
            chkAuthorized.Enabled = true;
            chkNarration.Enabled = true;
            chkDefualNarration.Enabled = true;
            chkRemark.Enabled = true;
            chkPrint.Enabled = true;
            chkGenerateVat.Enabled = true;
            chkCenvat.Enabled = true;
            chkShowItemName.Checked = true;

            chkShowItemCode.Checked = false;
            panelJrnlType.Visible = false;
            reqJournlStock.Enabled = false;
            chkNote.Enabled = false;
            chkRateAmount.Enabled = false;
            chkTrackPending.Enabled = false;


        }
        else if (ddlTransaction.SelectedValue == "3")//Sales Return
        {
            
            lblHeading.Text = "Invoice/DC Heading";
            Reset_chekbox();
           
            //************Tab Tax & Discount***********//
            //panelDiscount.Enabled = false;
            radioDBillLevel.Enabled = false;
            radioDItemLevel.Enabled = false; 
            radioDNone.Checked = true;
            radioDItemLevel.Checked = false;
            radioDBillLevel.Checked = false;           
            radioDNone.Enabled = false;

            radioTBillLevel.Checked = true;
            radioTBillLevel.Enabled = true;
            radioTItemLevel.Enabled = true;
            radioTItemLevel.Checked = false;
            txtRoundoff.Enabled = true;
            txtDiscount.Enabled = false;
           
            

            //************Tab Tax & Discount***********//
            chkAmtIncTax.Enabled = true;
            chkPreTax.Enabled = true;
            chkPostTax.Enabled = true;
            chkDelivery.Enabled = true;
            chkReference.Enabled = true;
            chkTermConditions.Enabled = true;
            chkPrepareBy.Enabled = true;
            chkCheckBy.Enabled = true;
            chkAuthorized.Enabled = true;
            chkNarration.Enabled = true;
            chkDefualNarration.Enabled = true;
            chkRemark.Enabled = true;
            chkPrint.Enabled = true;
            chkShowItemName.Checked = true;

            chkShowItemCode.Checked = false;
            panelJrnlType.Visible = false;
            reqJournlStock.Enabled = false;
            chkGenerateVat.Enabled = false;
            chkCenvat.Enabled = false;
            chkNote.Enabled = false;
            chkRateAmount.Enabled = false;
            chkTrackPending.Enabled = false;
        }
        else if (ddlTransaction.SelectedValue == "4")//Purchase Invoice
        {
            
            lblHeading.Text = "Invoice/DC Heading";
           
            Reset_chekbox();
            
            //************Tab Tax & Discount***********//
            panelDiscount.Enabled = true;
            radioDBillLevel.Enabled = true;
            radioDItemLevel.Enabled = true;
            radioDNone.Checked = true;
            radioDNone.Enabled = true;

            radioTBillLevel.Checked = true;
            radioTBillLevel.Enabled = true;
            radioTItemLevel.Enabled = true;
            txtRoundoff.Enabled = true;
            txtDiscount.Enabled = true;
            radioDItemLevel.Checked = false;
            radioDBillLevel.Checked = false;
            radioTItemLevel.Checked = false;

            //************Tab Tax & Discount***********//
            chkAmtIncTax.Enabled = true;
            chkPreTax.Enabled = true;
            chkPostTax.Enabled = true;
            chkDelivery.Enabled = true;
            chkReference.Enabled = true;
            chkPrepareBy.Enabled = true;
            chkCheckBy.Enabled = true;
            chkAuthorized.Enabled = true;
            chkNarration.Enabled = true;
            chkDefualNarration.Enabled = true;
            chkRemark.Enabled = true;
            chkCenvat.Enabled = true;
            chkShowItemName.Checked = true;

            chkShowItemCode.Checked = false;
            panelJrnlType.Visible = false;
            reqJournlStock.Enabled = false;
            chkPrint.Enabled = false;
            chkGenerateVat.Enabled = false;
            chkTermConditions.Enabled = false;
            chkNote.Enabled = false;
            chkRateAmount.Enabled = false;
            chkTrackPending.Enabled = false;
           
        }
        else if (ddlTransaction.SelectedValue == "6")//Purchse Return
        {
           
            lblHeading.Text = "Invoice/DC Heading";
            Reset_chekbox();
            
            //************Tab Tax & Discount***********//
           // panelDiscount.Enabled = false;
            radioDBillLevel.Enabled = false;
            radioDItemLevel.Enabled = false;
            radioDItemLevel.Checked = false;
            radioDBillLevel.Checked = false;
            radioDNone.Checked = true;
            radioDNone.Enabled = false;

            radioTBillLevel.Checked = true;           
            radioTBillLevel.Enabled = true;
            radioTItemLevel.Enabled = true;
            radioTItemLevel.Checked = false;
            txtRoundoff.Enabled = true;
            txtDiscount.Enabled = false;
           
           

            //************Tab Tax & Discount***********//
            chkAmtIncTax.Enabled = true;
            chkPreTax.Enabled = true;
            chkPostTax.Enabled = true;
            chkDelivery.Enabled = true;
            chkReference.Enabled = true;
            chkPrepareBy.Enabled = true;
            chkCheckBy.Enabled = true;
            chkAuthorized.Enabled = true;
            chkNarration.Enabled = true;
            chkDefualNarration.Enabled = true;
            chkRemark.Enabled = true;
            chkTermConditions.Enabled = true;
            chkShowItemName.Checked = true;

            chkShowItemCode.Checked = false;
            panelJrnlType.Visible = false;
            reqJournlStock.Enabled = false;
            chkPrint.Enabled = false;
            chkGenerateVat.Enabled = false;
            chkCenvat.Enabled = false;
            chkNote.Enabled = false;
            chkRateAmount.Enabled = false;
            chkTrackPending.Enabled = false;
        }
        else if (ddlTransaction.SelectedValue == "5")//DC Inward
        {
            lblHeading.Text = "Invoice/DC Heading";
            Reset_chekbox();
            
            //************Tab Tax & Discount***********//
            panelDiscount.Enabled = true;
            radioDBillLevel.Enabled = false;
            radioDItemLevel.Enabled = false;
            radioDNone.Checked = true;

            radioTBillLevel.Checked = true;
            radioTItemLevel.Enabled = false;
            txtRoundoff.Enabled = false;
            txtDiscount.Enabled = false;
            radioDItemLevel.Checked = false;
            radioDBillLevel.Checked = false;
            radioTItemLevel.Checked = false;
            //************Tab Tax & Discount***********//
            chkDelivery.Enabled = true;
            chkReference.Enabled = true;
            chkPrepareBy.Enabled = true;
            chkCheckBy.Enabled = true;
            chkAuthorized.Enabled = true;
            chkRemark.Enabled = true;
            chkNote.Enabled = true;
            chkRateAmount.Enabled = true;
            chkTrackPending.Enabled = true;
            chkShowItemName.Checked = true;

            chkShowItemCode.Checked = false;
            panelJrnlType.Visible = false;
            reqJournlStock.Enabled = false;
            chkPreTax.Enabled = false;
            chkPostTax.Enabled = false;
            chkNarration.Enabled = false;
            chkDefualNarration.Enabled = false;
            chkTermConditions.Enabled = false;
            chkAmtIncTax.Enabled = false;
            chkPrint.Enabled = false;
            chkGenerateVat.Enabled = false;
            chkCenvat.Enabled = false;

        }
        else if (ddlTransaction.SelectedValue == "2")//DC Outward
        {
            lblHeading.Text = "DC Heading";
            
            Reset_chekbox();
            //************Tab Tax & Discount***********//
            panelDiscount.Enabled = true;
            radioDBillLevel.Enabled = false;
            radioDItemLevel.Enabled = false;
            radioDNone.Checked = true;

            radioTBillLevel.Checked = true;
            radioTItemLevel.Enabled = false;
            txtRoundoff.Enabled = false;
            txtDiscount.Enabled = false;
            radioDItemLevel.Checked = false;
            radioDBillLevel.Checked = false;
            radioTItemLevel.Checked = false;
            //************Tab Tax & Discount***********//
            chkDelivery.Enabled = true;
            chkReference.Enabled = true;
            chkPrepareBy.Enabled = true;
            chkCheckBy.Enabled = true;
            chkAuthorized.Enabled = true;
            chkRemark.Enabled = true;
            chkNote.Enabled = true;
            chkRateAmount.Enabled = true;
            chkTrackPending.Enabled = true;
            chkPrint.Enabled = true;
            chkGenerateVat.Enabled = true;
            chkTermConditions.Enabled = true;
            chkShowItemName.Checked = true;

            chkShowItemCode.Checked = false;
            panelJrnlType.Visible = false;
            reqJournlStock.Enabled = false;
            chkPreTax.Enabled = false;
            chkPostTax.Enabled = false;
            chkNarration.Enabled = false;
            chkDefualNarration.Enabled = false;
            chkAmtIncTax.Enabled = false;
            chkCenvat.Enabled = false;
        }
        else if (ddlTransaction.SelectedValue == "7")//Stock Journal
        {
            lblHeading.Text = "Invoice/DC Heading";
           
            Reset_chekbox();
            //************Tab Tax & Discount***********//
            panelDiscount.Enabled = true;
            radioDBillLevel.Enabled = false;
            radioDItemLevel.Enabled = false;
            radioDNone.Checked = true;

            radioTBillLevel.Checked = true;
            radioTItemLevel.Enabled = false;
            txtRoundoff.Enabled = false;
            txtDiscount.Enabled = false;
            radioDItemLevel.Checked = false;
            radioDBillLevel.Checked = false;
            radioTItemLevel.Checked = false;
            //************Tab Tax & Discount***********//
            panelJrnlType.Visible = true;
            reqJournlStock.Enabled = true;
            chkPrepareBy.Enabled = true;
            chkCheckBy.Enabled = true;
            chkAuthorized.Enabled = true;
            chkRemark.Enabled = true;
            chkNote.Enabled = true;
            chkNarration.Enabled = true;
            chkShowItemName.Checked = true;

            chkShowItemCode.Checked = false;
            chkDelivery.Enabled = false;
            chkReference.Enabled = false;
            chkRateAmount.Enabled = false;
            chkTrackPending.Enabled = false;
            chkPrint.Enabled = false;
            chkGenerateVat.Enabled = false;
            chkTermConditions.Enabled = false;
            chkPreTax.Enabled = false;
            chkPostTax.Enabled = false;
            chkDefualNarration.Enabled = false;
            chkAmtIncTax.Enabled = false;
            chkCenvat.Enabled = false;
        }
        else if (ddlTransaction.SelectedValue == "8")//Purchase Order
        {
            lblHeading.Text = "Invoice/DC Heading";
            Reset_chekbox();

            //************Tab Tax & Discount***********//
            panelDiscount.Enabled = false;
            radioDBillLevel.Enabled = false;
            radioDItemLevel.Enabled = false;
            radioDNone.Checked = true;
            radioDNone.Enabled = false;

            radioTBillLevel.Checked = true;
            radioTItemLevel.Enabled = true;
            txtRoundoff.Enabled = true;
            txtDiscount.Enabled = false;
            radioDItemLevel.Checked = false;
            radioDBillLevel.Checked = false;
            radioTItemLevel.Checked = false;

            //************Tab Tax & Discount***********//
            chkAmtIncTax.Enabled = true;
            chkPreTax.Enabled = true;
            chkPostTax.Enabled = true;
            chkDelivery.Enabled = true;            
            chkPrepareBy.Enabled = true;
            chkCheckBy.Enabled = true;
            chkAuthorized.Enabled = true;
            chkNarration.Enabled = true;
            chkDefualNarration.Enabled = true;
            chkRemark.Enabled = true;
            chkTermConditions.Enabled = true;
            chkShowItemName.Checked = true;

            chkShowItemCode.Checked = false;
            chkReference.Enabled = false;
            panelJrnlType.Visible = false;
            reqJournlStock.Enabled = false;
            chkPrint.Enabled = false;
            chkGenerateVat.Enabled = false;
            chkCenvat.Enabled = false;
            chkNote.Enabled = false;
            chkRateAmount.Enabled = false;
            chkTrackPending.Enabled = false;
        }
        else if (ddlTransaction.SelectedValue == "9")//Sales Order
        {
            lblHeading.Text = "Invoice/DC Heading";
            Reset_chekbox();

            //************Tab Tax & Discount***********//
            panelDiscount.Enabled = false;
            radioDBillLevel.Enabled = false;
            radioDItemLevel.Enabled = false;
            radioDNone.Checked = true;
            radioDNone.Enabled = false;

            radioTBillLevel.Checked = true;
            radioTItemLevel.Enabled = true;
            txtRoundoff.Enabled = true;
            txtDiscount.Enabled = false;
            radioDItemLevel.Checked = false;
            radioDBillLevel.Checked = false;
            radioTItemLevel.Checked = false;

            //************Tab Tax & Discount***********//
            chkAmtIncTax.Enabled = true;
            chkPreTax.Enabled = true;
            chkPostTax.Enabled = true;
            chkDelivery.Enabled = true;            
            chkTermConditions.Enabled = true;
            chkPrepareBy.Enabled = true;
            chkCheckBy.Enabled = true;
            chkAuthorized.Enabled = true;
            chkNarration.Enabled = true;
            chkDefualNarration.Enabled = true;
            chkRemark.Enabled = true;
            chkPrint.Enabled = true;
            chkShowItemName.Checked = true;

            chkShowItemCode.Checked = false;
            chkReference.Enabled = false;
            panelJrnlType.Visible = false;
            reqJournlStock.Enabled = false;
            chkGenerateVat.Enabled = false;
            chkCenvat.Enabled = false;
            chkNote.Enabled = false;
            chkRateAmount.Enabled = false;
            chkTrackPending.Enabled = false;
        }


    }
    protected void DisableTabs()
    {
        //TabContainer.Enabled = false;
        //tabTransSetting.Enabled = false;
        //tabTaxSettings.Enabled = false;
        //tabNumberSettings.Enabled = false;
        //tabHeading.Enabled = false;
        //tabDeclaration.Enabled = false;
        
    }
    protected void EnableTabs()
    {
        //TabContainer.Enabled = true;
        //tabTransSetting.Enabled = true;
        //tabTaxSettings.Enabled = true;
        //tabNumberSettings.Enabled = true;
        //tabHeading.Enabled = true;
        //tabDeclaration.Enabled = true;
        
    }

    protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if(ddlType.SelectedValue=="0")
        {
            txtStartNo.Enabled = false;
            txtStartNo.Text = "0";
            txtWidthofNo.Enabled = false;
            chkResetYear.Enabled = false;
            chkFillZero.Enabled = false;
        }
        else if (ddlType.SelectedValue == "1")
        {
            txtStartNo.Enabled = true;
            txtWidthofNo.Enabled = true;
            txtStartNo.Text = "1";
            chkResetYear.Enabled = true;
            chkFillZero.Enabled = true;

        }
    }
    protected bool Validate()
    {
        strsql = "Select FORMATNAME from IVR_TRANFORMAT where FORMATNAME='"+txtFormatName.Text.Trim()+"' ";
        DataTable DT = DU.getdata(strsql);
        if (DT.Rows.Count > 0)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Duplicate Format Name');", true);
            return false;  
        }
        else
        {
            return true;
        }
    }

    protected void Insert_TranFormat_Main()
    {
        
            int RoundOff_Led = 0;
            string TaxAtItem = "";
            int Discount = 0;
            int Discount_Led = 0;
            string ItemType = "0";
            if (radioTBillLevel.Checked == true)
            {
                TaxAtItem = "False";
            }
            else if (radioTItemLevel.Checked == true)
            {
                TaxAtItem = "True";
            }
            if (radioDNone.Checked == true)
            {
                Discount = 0;
            }
            else if (radioDBillLevel.Checked == true)
            {
                Discount = 1;
            }
            else if (radioDItemLevel.Checked == true)
            {
                Discount = 2;
            }
            if (txtRoundoff.Text != string.Empty)
            {
                RoundOff_Led = 1;
            }
            else
            {
                RoundOff_Led = 0;
            }
            if (txtDiscount.Text != null)
            {
                Discount_Led = 1;
            }
            else
            {
                Discount_Led = 0;
            }
            if (chkShowItemName.Checked == true)
            {
                ItemType = "0";
            }
            else if (chkShowItemCode.Checked == true)
            {
                ItemType = "1";
            }
            string spname = "USP_IVR_SaveTransactionFormat";
            SqlParameter[] sparam =
                                {
                                    new SqlParameter ("@TRANTYPE",ddlTransaction.SelectedValue),
                                    new SqlParameter ("@FORMATNAME",txtFormatName.Text),
                                    new SqlParameter ("@DCWITHAMOUNT",chkRateAmount.Checked),
                                    new SqlParameter ("@ROUNDOFF_LID",RoundOff_Led.ToString()),
                                    new SqlParameter ("@DISCOUNT_LID",Discount_Led.ToString()),
                                    new SqlParameter ("@TAXATITEM",TaxAtItem.ToString()),
                                    new SqlParameter ("@DISCATITEM",Discount.ToString()),
                                    new SqlParameter ("@SETASDEFAULT",chkDefualt.Checked),
                                    new SqlParameter ("@ITEMADDNDESC",chkAddDescItem.Checked),
                                    new SqlParameter ("@AMOUNTINCLUTAX",chkAmtIncTax.Checked),
                                    new SqlParameter ("@TRANREF",chkReference.Checked),
                                    new SqlParameter ("@TERMSCONDITIONS",chkTermConditions.Checked),
                                    new SqlParameter ("@PRETAXCHARGES",chkPreTax.Checked),
                                    new SqlParameter ("@POSTTAXCHARGES",chkPostTax.Checked),
                                    new SqlParameter ("@NARRATION",chkNarration.Checked),
                                    new SqlParameter ("@DEFAULTNARRATION",chkDefualNarration.Checked),
                                    new SqlParameter ("@NOTE",chkNote.Checked),
                                    new SqlParameter ("@REMARKS",chkRemark.Checked),
                                    new SqlParameter ("@PREPAREDBY",chkPrepareBy.Checked),
                                    new SqlParameter ("@CHECKEDBY",chkCheckBy.Checked),
                                    new SqlParameter ("@AUTHSIGNATORY",chkAuthorized.Checked),
                                    new SqlParameter ("@POSTBILLING",chkPostBillTCS.Checked),
                                    new SqlParameter ("@PRINTONSAVE",chkPrint.Checked),
                                    new SqlParameter ("@ITEMTYPE",ItemType.ToString()),
                                    new SqlParameter ("@VAT505ONSAVE",chkGenerateVat.Checked),
                                    new SqlParameter ("@DELIVERYDETAILS",chkDelivery.Checked),
                                    new SqlParameter ("@STKJRNLOPT",ddlJrnlType.SelectedValue),
                                    new SqlParameter ("@INVDCHEADING",txtInvoiceHeading.Text),
                                    new SqlParameter ("@DCTRACKPENDING",chkTrackPending.Checked),
                                    new SqlParameter ("@DOCNUMCAP",txtDocumnetNo.Text),
                                    new SqlParameter ("@TRANDECLARATION",txtDeclaration.Text),
                                    new SqlParameter ("@CENVAT",chkCenvat.Checked),
                                    new SqlParameter ("@BILLLEVELTARIFF",chkBillLevelTariff.Checked),
                                    new SqlParameter ("@cname",Session["username"].ToString())
                                };
            int result = DU.executeprocedure(spname, sparam);
            if (result > 0)
            {
                strsql = "Select Ident_current('IVR_TRANFORMAT') as TFOID";
                DataTable DTTfoid = DU.getdata(strsql);
                if (DTTfoid.Rows.Count > 0)
                {
                    TFOID = DTTfoid.Rows[0]["TFOID"].ToString();
                }

            }
       
    }
    protected void Insert_TranFormat_Tariff()
    {

        if (TFOID.ToString() != string.Empty)
        {

            string spname = "USP_IVR_SaveTransactionFormatTariffDetail";
            SqlParameter[] sparam =
                                {
                                    new SqlParameter("@TFOID",TFOID.ToString()),
                                    new SqlParameter("@HEADING",txtTariffHeading.Text),
                                    new SqlParameter("@SUBHEADING",txtTariffSubHeading.Text),
                                    new SqlParameter("@TARIFFDESCRIPTION",txtTariffDescription.Text)
                                };
            int result = DU.executeprocedure(spname, sparam);
        }
                                    
                          
    }
    protected void Insert_TranFormat_Recaption()
    {
        if (TFOID.ToString() != string.Empty)
        {

            string spname = "USP_IVR_SaveTransactionReferenceCaptions";
            SqlParameter[] sparam1 =
                                {
                                    new SqlParameter("@TFOID",TFOID.ToString()),
                                    new SqlParameter("@REFID","1"),
                                    new SqlParameter("@REFCAPTION ",txtRefHeading1.Text),
                                    
                                };
            int result1 = DU.executeprocedure(spname, sparam1);
            SqlParameter[] sparam2 =
                                {
                                    new SqlParameter("@TFOID",TFOID.ToString()),
                                    new SqlParameter("@REFID","2"),
                                    new SqlParameter("@REFCAPTION ",txtRefHeading2.Text),
                                    
                                };
            int result2 = DU.executeprocedure(spname, sparam2);
            SqlParameter[] sparam3 =
                                {
                                    new SqlParameter("@TFOID",TFOID.ToString()),
                                    new SqlParameter("@REFID","3"),
                                    new SqlParameter("@REFCAPTION ",txtRefHeading3.Text),
                                    
                                };
            int result3 = DU.executeprocedure(spname, sparam3);
            SqlParameter[] sparam4 =
                                {
                                    new SqlParameter("@TFOID",TFOID.ToString()),
                                    new SqlParameter("@REFID","4"),
                                    new SqlParameter("@REFCAPTION ",txtRefHeading4.Text),
                                    
                                };
            int result4 = DU.executeprocedure(spname, sparam4);
        }
    }
    protected void Insert_TranFormat_Numbering()
    {
        if (TFOID.ToString() != string.Empty)
        {

            if (txtWidthofNo.Text.Trim() == "")
            {
                txtWidthofNo.Text = "0";
            }


            string spname = "USP_IVR_SaveTrasactionNumberFormat";
            SqlParameter[] sparam =
                                {
                                    new SqlParameter("@TFOID",TFOID.ToString()),
                                    new SqlParameter("@FINYEAR","2010"),
                                    new SqlParameter("@NUMBERINGMETHOD",ddlType.SelectedValue),
                                    new SqlParameter("@NUMPREFIX",txtPrefix.Text.Trim()),
                                    new SqlParameter("@NUMSTART",txtStartNo.Text.Trim()),
                                    new SqlParameter("@NUMSUFFIX",txtSuffix.Text.Trim()),
                                    new SqlParameter("@NUMDIGITS",txtWidthofNo.Text.Trim()),
                                    new SqlParameter("@NUMPREFILLZERO",chkFillZero.Checked),
                                    new SqlParameter("@RESETOPT",chkResetYear.Checked)
                                };
            int result = DU.executeprocedure(spname, sparam);
        }

    }

    protected void InsertTransactionMain()
    {
        try
        {
            int AccParentTypeId = 0;
            if (ddlTransaction.SelectedValue == "4")
            {
                AccParentTypeId = 7;
            }
            else if (ddlTransaction.SelectedValue == "6")
            {
                AccParentTypeId = 8;
            }
            else if (ddlTransaction.SelectedValue == "1")
            {
                AccParentTypeId = 10;
            }
            else if (ddlTransaction.SelectedValue == "3")
            {
                AccParentTypeId = 11;
            }
            else 
            {
                AccParentTypeId = 0;
            }
 
            
            string[] Date1 = string.Format("{0:MM/dd/yyyy}", Convert.ToDateTime(System.DateTime.Now)).ToString().Split('/');
            string effectiveDate = Date1[0].ToString() + "/" + Date1[1].ToString() + "/" + Date1[2].ToString();

            SqlParameter[] sparam =
                                        {
                                            
                                            new SqlParameter("@TYPEID","-1"),
                                            new SqlParameter("@PARENTTYPEID",AccParentTypeId.ToString()),
                                            new SqlParameter("@TRANSACTIONNAME",txtFormatName.Text.Trim()),
                                            new SqlParameter("@ISAUTONO",ddlType.SelectedValue),
                                            new SqlParameter("@RESETNO",chkResetYear.Checked),
                                            new SqlParameter("@ISREFERENCE","0"),                                                
                                            new SqlParameter("@ISDEFAULTNARRATION","0"),
                                            new SqlParameter("@EFFECTIVEDATE",effectiveDate.ToString()),
                                            new SqlParameter("@BILLFORMATID",TFOID.ToString()),
                                            new SqlParameter("@MODULETYPE","2"),
                                            new SqlParameter("@CCALLOCATIONTYPE","0")
                                        };
            int result = DU.executeprocedure("USP_ACC_SaveTransactionSetting", sparam);
            if (result > 0)
            {
                strsql = "Select Ident_Current('ACC_TRANSETTINGS') as TYPEID";
                DataTable DT = DU.getdata(strsql);
                if (DT.Rows.Count > 0)
                {
                    AccTypeId = DT.Rows[0]["TYPEID"].ToString();
                }
            }
        }
        catch (Exception ex)
        {
            string str = ex.Message;            
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('" + str + "');", true);
        }
    }
    
    protected void InsertTransactionDetails()
    {
        try
        {
            if (AccTypeId.ToString() != string.Empty)
            {
                
                SqlParameter[] sparam =
                                            {
                                                new SqlParameter("@TYPEID",AccTypeId.ToString()),
                                                new SqlParameter("@STARTNO",txtStartNo.Text.Trim()),
                                                new SqlParameter("@FINYEAR","2010"),
                                                new SqlParameter("@PREFIX",txtPrefix.Text.Trim()),
                                                new SqlParameter("@SUFFIX",txtSuffix.Text.Trim()),
                                                new SqlParameter("@ACCLEVELNARRATION","0"),
                                                new SqlParameter("@PRINTONSAVE","0")

                                            };
                DU.executeprocedure("USP_ACC_SaveTransactionSettingDetail", sparam);
                
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Type ID is Empty');", true);
            }
        }
        catch (Exception ex)
        {
            string str = ex.Message;
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('"+str.ToString()+"');", true);
        }

    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string msg = "";
        try
        {
            if (Validate())
            {
                Insert_TranFormat_Main();
                Insert_TranFormat_Tariff();
                Insert_TranFormat_Recaption();
                Insert_TranFormat_Numbering();
                InsertTransactionMain();
                InsertTransactionDetails();
                msg = "Update Successfully";
                AlertBox(msg);
            }
        }
        catch (Exception ex)
        {
            msg = ex.Message;
            AlertBox(msg);
        }
    }
    protected void btnClose_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Welcome.aspx");
    }
    protected void AlertBox(string Message)
    {
        ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('" + Message + "');", true);
    }
}





//CheckBox chkAmtIncTax = (CheckBox)TabContainer.FindControl("chkAmtIncTax");
//CheckBox chkPreTax = (CheckBox)TabContainer.FindControl("chkPreTax");
//CheckBox chkPostTax = (CheckBox)TabContainer.FindControl("chkPostTax");
//CheckBox chkDelivery = (CheckBox)TabContainer.FindControl("chkDelivery");
//CheckBox chkReference = (CheckBox)TabContainer.FindControl("chkReference");
//CheckBox chkTermConditions = (CheckBox)TabContainer.FindControl("chkTermConditions");
//CheckBox chkPrepareBy = (CheckBox)TabContainer.FindControl("chkPrepareBy");

//CheckBox chkCheckBy = (CheckBox)TabContainer.FindControl("chkCheckBy");
//CheckBox chkAuthorized = (CheckBox)TabContainer.FindControl("chkAuthorized");
//CheckBox chkNarration = (CheckBox)TabContainer.FindControl("chkNarration");
//CheckBox chkDefualNarration = (CheckBox)TabContainer.FindControl("chkDefualNarration");
//CheckBox chkRemark = (CheckBox)TabContainer.FindControl("chkRemark");
//CheckBox chkPrint = (CheckBox)TabContainer.FindControl("chkPrint");
//CheckBox chkGenerateVat = (CheckBox)TabContainer.FindControl("chkGenerateVat");
//CheckBox chkCenvat = (CheckBox)TabContainer.FindControl("chkCenvat");
//CheckBox chkNote = (CheckBox)TabContainer.FindControl("chkNote");
//CheckBox chkRateAmount = (CheckBox)TabContainer.FindControl("chkRateAmount");
//CheckBox chkTrackPending = (CheckBox)TabContainer.FindControl("chkTrackPending");

